package org.example.myleet.p769;

public class Solution {
    public int maxChunksToSorted(int[] arr) {
        int n = arr.length;
        int[] map = new int[n];
        int mapSize = 0, res = 0;
        for (int i = 0; i < n; ++i) {
            ++map[i];
            if (map[i] == 0) {
                --mapSize;
            } else {
                ++mapSize;
            }
            --map[arr[i]];
            if (map[arr[i]] == 0) {
                --mapSize;
            } else {
                ++mapSize;
            }
            if (mapSize == 0) {
                ++res;
            }
        }
        return res;
    }
}
